//
// Created by xuwj on 2021/11/8.
//

#ifndef CV_ASSISTANT_SMALLTOOLS_H
#define CV_ASSISTANT_SMALLTOOLS_H

#include "ImageProcessing/common_xu.h"

using namespace std;

namespace CV_Assistant{
namespace ImageProcessing{

    struct rectangle_corners{
        cv::Point2i left_top_;
        cv::Point2i right_bottom_;

        rectangle_corners(){
            left_top_ = cv::Point2i(0,0);
            right_bottom_ = cv::Point2i(0,0);
        }
    };

    enum MergeFlags{
         WithRight    =    1,
         WithBottom   =    2,
         WithTop      =    3,
         WithLeft     =    4
    };

    /**stitch two images together and give back one image merged by the two,
     * if the rows or cols are not aligned, we will merge after resizing the small one
     * @param src_a
     * @param src_b
     * @param dst
     * @param flag  src_b's position to src_a
     */
    void Merge(const cv::Mat &src_a,const cv::Mat &src_b, cv::Mat &dst, int flag = WithRight);

    /**The same function as Merge(), but the two input images has been aligned with the orientation
     * @param src_a
     * @param src_b
     * @param dst
     * @param flag
     */
    void MergeEqual(const cv::Mat &src_a,const cv::Mat &src_b, cv::Mat &dst, int flag = WithRight);

    /**
     * Input a image with distinctive X-Y orientation (Orthogonal),
     * this function rotate it to make the distinctive-XY fit the Pixel-Coordinate-XY (using lines-detection)
     * @param src
     * @param dst
     * @param CannyParams
     * @param HoughParams
     */
    void RotateToXY(const cv::Mat &src, cv::Mat &dst,
                    const double* CannyParams, const double* HoughParams,
                    const int center_driftX = 0, const int center_driftY = 0);


    /**
     * Class for all kinds of Mouse-Callback-Function to directly operate on images
     */
    class ImageOnMouse{
    public:
        ImageOnMouse(const std::string win_name);

        ImageOnMouse(const std::string win_name,const cv::Mat &img);

        std::string GetWinName(){
            return win_name_;
        }

        bool showImage();
        bool showImage(cv::Mat &img);

        //set mouseCallback function to ...
        void setCB_PointCoordinate();
        void setCB_ChangeAreaPixelValue();

//        friend void CB_PointCoordinate(int event, int x, int y, int flags, void* userdata);

    public:
        cv::Mat image_;
//        cv::Mat temp_paint;

        static int font_type;
        static double font_scale;
        static int font_thickness;
        static cv::Scalar font_color;

        // for drawing and mouse-interacting
        rectangle_corners rect_;
        bool select_flag_;

    private:
        std::string win_name_;
    };

//namespace ImageProcessing
}
//namespace CV_Assistant
}


#endif //CV_ASSISTANT_SMALLTOOLS_H
